package com.level2app.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.QuickViewHolder;
import com.level2app.R;
import com.level2app.utils.ScreenUtil;
import com.level2app.view.FlowLayoutManager;
import com.level2app.view.SpaceItemDecoration;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by S
 * time 2024/8/17
 */
public class CategoriesListAdapter extends BaseQuickAdapter<String, QuickViewHolder> {

    @Override
    protected void onBindViewHolder(@NonNull QuickViewHolder holder, int i, @Nullable String bean) {
        holder.setText(R.id.titleTv, "The Goodtime Hotel");
        holder.setText(R.id.locationTv, "Miami Beach, FL");
//        holder.setText(R.id.contentTv, "Up to $350 Bonus");
        Glide.with(getContext()).load("https://img2.baidu.com/it/u=1237025922,2679733234&fm=253&fmt=auto&app=120&f=JPEG?w=749&h=500").into((ImageView) holder.getView(R.id.roundedIv));

        RecyclerView recyclerView = holder.getView(R.id.itemRv);
        FlowLayoutManager flowLayoutManager = new FlowLayoutManager();
        recyclerView.setLayoutManager(flowLayoutManager);
        FlowLayoutItemAdapter adapter = new FlowLayoutItemAdapter();
        if (holder.itemView.getTag() == null) {
            recyclerView.addItemDecoration(new SpaceItemDecoration(ScreenUtil.dip2px(3)));
            holder.itemView.setTag("item");
        }
        recyclerView.setAdapter(adapter);

        List<String> data = new ArrayList<>();
        data.add("1 Room Left");
        data.add("Hotel");
        adapter.submitList(data);
    }

    @NonNull
    @Override
    protected QuickViewHolder onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        return new QuickViewHolder(R.layout.item_categories_list, viewGroup);
    }
}